package com.wuwie.article.controller;

import com.wuwie.article.entity.Comment;
import com.wuwie.article.entity.SubComment;
import com.wuwie.article.service.CommentService;
import com.wuwie.article.service.SubCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;


@RestController
public class CommentController {


    @Autowired
    private CommentService commentService;


    @Autowired
    private SubCommentService subCommentService;


    @DeleteMapping("/comment")
    public long delcommentr(String id){
        long del = commentService.delcomment(id);
        return del;
    }

    @PostMapping("/comment")
    public Integer addcomment(Comment comment){
        System.out.println(comment.getContent());
        List<Comment> select = commentService.select();
        Integer i = select.size() + 1;
        String id = String.valueOf(i);
        comment.setId(id);
        comment.setArticleid("1001");
        comment.setUserid("108");
        comment.setNickname("夏敏@夏至");
        comment.setCreatedatetime(new Date());
        comment.setLikenum(0);
        comment.setReplynum(0);
        comment.setState("1");
        comment.setParentid("0");
        Integer addcomment = commentService.addcomment(comment);
        return addcomment;
    }
    @GetMapping("/subcomment")
    public List<SubComment> select(){
        List<SubComment> select = subCommentService.select();
        return select;
    }




    @DeleteMapping("/subcomment")
    public long delcomment(String id){
        long delcomment = subCommentService.delcomment(id);
        return delcomment;
    }



    @PostMapping("/subcomment")
    public Integer Subaddcomment(SubComment subComment){
        List<SubComment> select = subCommentService.select();
        Integer i = select.size() + 1;
        String id = String.valueOf(i);
        subComment.setId(id);
        subComment.setArticleid("1001");
        subComment.setUserid("108");
        subComment.setNickname("夏敏@夏至");
        subComment.setCreatedatetime(new Date());
        subComment.setLikenum(0);
        subComment.setReplynum(0);
        subComment.setState("1");
        Integer Subaddcomment = subCommentService.Subaddcomment(subComment);
        return Subaddcomment;
    }
}
